package com.isaac.service;

import com.isaac.MethodService;

import java.util.concurrent.ThreadLocalRandom;

public class MethodServiceThread extends Thread{

    private final MethodService methodService;

    public MethodServiceThread(MethodService methodService){
        super();
        this.methodService = methodService;
    }

    @Override
    public void run() {
        super.run();


        // 判断调用哪个方法
        int i = ThreadLocalRandom.current().nextInt(3);
        int sleepMills = ThreadLocalRandom.current().nextInt(100);
        String response = "";
        switch (i){
            case 0:
                response = methodService.methodA(String.valueOf(sleepMills), sleepMills);
                break;
            case 1:
                response = methodService.methodB(String.valueOf(sleepMills), sleepMills);
                break;
            case 2:
                response = methodService.methodC(String.valueOf(sleepMills), sleepMills);
                break;
            default:
                break;
        }
        System.out.println(Thread.currentThread().getName() + "调用结果:[" + response + "]");
    }
}
